<?php
 
namespace app\common\job;
 
use Yii;
use yii\base\BaseObject;
use app\helpers\DatetimeHelper;
use app\common\components\WxOfficial;
use app\modules\wxofficial\service\WxOfficialService;
 
class WxOfficialJob extends BaseObject implements \yii\queue\Job
{
    public $userId;
    public $sendUserId;
    public $type;
    public $templateId;
    public $param=null;
    public $openid;
    public $jumpUrl;
    public function execute($queue)
    {
        $res = (new WxOfficial)->sendOne($this->templateId, $this->param, $this->openid, $this->jumpUrl);
        $res = json_decode($res);
        $addData = [
            'user_id' => (string)$this->userId,
            'send_user_id' => (string)$this->sendUserId,
            'openid' => (string)$this->openid,
            'type' => (string)$this->type,
            'template_id' => (string)$this->templateId,
            'template_param' => json_encode($this->param),
            'res_message' => (string)$res->errmsg ?? '',
            'response_code' => (string)$res->errcode ?? '',
            'msgid' => (string)$res->msgid ?? '',
            'create_timestamp' => DatetimeHelper::msectime(),
        ];
        print_r($addData);
        (new WxOfficialService)->add($addData);
    }
 
}